package J5923;

/**
 * 从房屋收集雨水需要的最少水桶数
 * @author 23737
 * @time 2021.11.28
 */
public class Test {
    public static void main(String[] args) {

    }
}

/*
计数法
 */
class Solution {
    public int minimumBuckets(String street) {
        if ("H".equals(street) || street.startsWith("HH") || street.endsWith("HH") || street.contains("HHH")) {
            return -1;
        }

        int res = 0;
        for (char c : street.toCharArray()) {
            if (c == 'H') {
                ++res;
            }
        }

        for (int i = 0; i < street.length() - 2; ++i) {
            if (street.charAt(i) == 'H' && street.charAt(i+1)=='.' && street.charAt(i+2)=='H') {
                --res;
                i += 2;
            }
        }
        return res;
    }
}
